<?php
/**
 * +----------------------------------------------------------------------
 * | Author: 罗极
 * +----------------------------------------------------------------------
 * | Description: EventBase.php
 * +----------------------------------------------------------------------
 * | User: Administrator Date: 8/20/ 0020 Time: 18:03
 * +----------------------------------------------------------------------
 */

namespace Framework\Event\Abstracts;
use Framework\Event\EventUnit;
use Framework\Event\Exceptioin\UnknownEvent;

abstract class EventBase
{

    protected $event = [];

    public function on(string $event, $obj, \Closure $callback)
    {
        $this->event[$event] = new EventUnit($event, $obj, $callback);
    }

    public function tigger(string $event)
    {
        if(!isset($this->event[$event])) {
            return ;
            throw new UnknownEvent(sprintf(
                '未知的事件触发:[%s]'
            ), $event);
        }

        $this->event[$event]->call();
        unset($this->event[$event]);
    }

    public function remove(string $event)
    {
        unset($this->event[$event]);
    }

}